/*
 * @(#)TicketAuction_Ja.java	1.17 01/08/21
 *
 * Copyright (c) 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

package example.auction.i18n;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class TicketAuction_Ja extends AuctionDemo_Ja {

    public void startApp() {
        notImpl = 
	    new Alert("\u8aa0\u306b\u7533\u3057\u8a33\u3042\u308a\u307e"
		      + "\u305b\u3093",
		      "\u73fe\u5728\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093",
		      null, null);

        savedMsg = 
	    new Alert(null, "\u3042\u306a\u305f\u306e\u65b0\u3057\u3044\u8a2d"
		      + "\u5b9a\u306f\u4fdd\u5b58\u3055\u308c\u307e"
		      + "\u3057\u305f",
		      null, null);

        alertMsg = 
	    new Alert(null, 
		      "\u3042\u306a\u305f\u306e\u65b0\u3057\u3044\u8a2d"
		      + "\u5b9a\u306f\u4fdd\u5b58\u3055\u308c"
		      + "\u307e\u3057\u305f",
		      null, null);

        // submitMsg = new Alert(null);
        // submitMsg.append("Submitting your bid...");
          submitGauge = new Gauge("", false, 100, 0);
          submitMsg = new Form("\u5165\u672d\u3092\u63d0\u51fa\u4e2d");
          submitMsg.append(submitGauge);


        ticker = new Ticker("");
        ticker.setString(band.toTickerString(null));

        aucMenu = new List("\u30aa\u30fc\u30af\u30b7\u30e7\u30f3",
			   Choice.IMPLICIT);
        aucMenu.append("\u51fa\u54c1\u30ea\u30b9\u30c8", null);
        aucMenu.append("\u5165\u672d\u3059\u308b", null);
        aucMenu.append("\u5165\u672d\u984d\u901a\u77e5\u8a2d\u5b9a", null);
        aucMenu.append("\u8a2d\u5b9a", null);
        aucMenu.append("\u30b3\u30d4\u30fc\u30e9\u30a4\u30c8", null);
        aucMenu.addCommand(BYE_CMD);
        aucMenu.setCommandListener(this);
        aucMenu.setTicker(ticker);
        display.setCurrent(aucMenu);

        bandList = new List("\u30a2\u30fc\u30c6\u30a3\u30b9\u30c8",
			    Choice.IMPLICIT);
        bandList.addCommand(BACK_CMD);
        bandList.setCommandListener(this);
        bandList.setTicker(ticker);
        String[] list = band.getList();
        for (int i = 0; i < list.length; i++) {
            bandList.append(list[i], null);
        }

        ticketList = new List("dummy", Choice.IMPLICIT);
        ticketList.addCommand(BACK_CMD);
        ticketList.setCommandListener(this);

        ticketForm = new Form("dummy");
        ticketForm.append("dummy");
        ticketForm.addCommand(BACK_CMD);
        ticketForm.addCommand(MENU_CMD);
        ticketForm.setCommandListener(this);

        enterText = new TextField("", "", 10, TextField.NUMERIC);

        enterForm = new Form("\u8a2d\u5b9a");
        enterForm.append("\u5165\u672d\u984d\u304c\u4ee5\u4e0b\u306e"
			 + "\u8a2d\u5b9a\u91d1\u984d\u306a\u308b\u3068"
			 + "\u304a\u77e5\u3089\u305b\u3057\u307e\u3059:");
        enterForm.append(enterText);
        enterForm.addCommand(BACK_CMD);
        enterForm.addCommand(SAVE_CMD);
        enterForm.setCommandListener(this);

        bidText = new TextField("", "", 10, TextField.NUMERIC);

        bidForm = new Form("dummy");
        bidForm.append("dummy");
        bidForm.append(bidText);
        bidForm.addCommand(BACK_CMD);
        bidForm.addCommand(NEXT_CMD);
        bidForm.setCommandListener(this);

        setMenu = new List("\u8a2d\u5b9a", Choice.IMPLICIT);
        setMenu.append("\u65e5\u4ed8\u8a2d\u5b9a", null);
        setMenu.append("\u30c6\u30ed\u30c3\u30d7", null);
        setMenu.append("\u30a2\u30e9\u30fc\u30e0\u9593\u9694", null);
        setMenu.append("\u30a2\u30fc\u30c6\u30a3\u30b9\u30c8\u8ffd\u52a0",
		       null);
        setMenu.append("\u30a2\u30fc\u30c6\u30a3\u30b9\u30c8\u524a\u9664",
		       null);
        setMenu.addCommand(BACK_CMD);
        setMenu.setCommandListener(this);
        setMenu.setTicker(ticker);

        addBand = new TextBox("\u8ffd\u52a0\u3059\u308b\u30a2\u30fc\u30c6"
			      + "\u30a3\u30b9\u30c8\u3092\u30b3\u30f3\u30de(,)"
			      + "\u3067\u533a\u5207\u3063\u3066\u5165\u529b"
			      + "\u3057\u3066\u304f\u3060\u3055\u3044"
			      + "Add Bands,\nBands:", "", 100, TextField.ANY);
        addBand.addCommand(BACK_CMD);
        addBand.addCommand(SAVE_CMD);
        addBand.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable s) {
        if (s instanceof List) {
            List obj = (List) s;
            if (obj == aucMenu) {
                if (c == List.SELECT_COMMAND) {
                    int idx = obj.getSelectedIndex();
                    switch (idx) {
                    case 0:
                        chooseBandType = 0;
                        display.setCurrent(bandList);
                        break;
                    case 1:
                        chooseBandType = 1;
                        display.setCurrent(bandList);
                        break;
                    case 2:
                        chooseBandType = 2;
                        display.setCurrent(bandList);
                        break;
                    case 3:
                        display.setCurrent(setMenu);
                        break;
                    case 4:
                        example.About.showAbout(display);
                        break;
                    }
                } else if (c == BYE_CMD) {
                    notifyDestroyed();
                }
            } else if (obj == bandList) {
                if (c == List.SELECT_COMMAND) {
                    int idx = obj.getSelectedIndex();
                    String bandName = band.getName(idx);
                    ticketList.setTitle(bandName);
                    reconstructList(ticketList, band.getTicketList(bandName));
                    display.setCurrent(ticketList);
                } else if (c == BACK_CMD) {
                    display.setCurrent(aucMenu);
                }
            } else if (obj == ticketList) {
                if (c == List.SELECT_COMMAND) {
                    int idx = obj.getSelectedIndex();
                    String bandName = ticketList.getTitle();
                    if (chooseBandType == 0) {
                        ticketForm.setTitle(bandName);
                        ticketForm.delete(0);
                        ticketForm.append(band.getTicketData(bandName, 
                                                                   idx));
                        display.setCurrent(ticketForm);
                    } else if (chooseBandType == 1) {
                        login.setID(bandName, band.getTicketID(bandName, idx));
                        bidForm.setTitle(null);
                        StringItem item = 
                            new StringItem("",
                                           band.getTicketBidTitle(bandName, 
                                                                  idx));
                        bidForm.set(0, item);
                        display.setCurrent(bidForm);
                    } else if (chooseBandType == 2) {
                        display.setCurrent(enterForm);
                    }
                } else if (c == BACK_CMD) {
                    display.setCurrent(bandList);
                }
            } else if (obj == setMenu) {
                if (c == List.SELECT_COMMAND) {
                    int idx = obj.getSelectedIndex();
                    switch (idx) {
                    case 0:
                        date.setDate();
                        display.setCurrent(date);
                        break;
                    case 1:
                        display.setCurrent(setTicker);
                        break;
                    case 2:
                        display.setCurrent(updateInt);
                        break;
                    case 3:
                        display.setCurrent(addBand);
                        break;
                    case 4:
                        display.setCurrent(rmBand);
                        break;
                    }
                } else if (c == BACK_CMD) {
                    display.setCurrent(aucMenu);
                }
            }
        } else if (s instanceof Form) {
            Form obj = (Form) s;
            if (obj == ticketForm) {
                if (c == BACK_CMD) {
                    display.setCurrent(ticketList);
                } else if (c == MENU_CMD) {
                    display.setCurrent(aucMenu);
                }
            } else if (obj == bidForm) {
                if (c == BACK_CMD) {
                    display.setCurrent(ticketList);
                } else if (c == NEXT_CMD) {
                    login.setBid(ticketList.getTitle(), bidText.getString());
                    display.setCurrent(login);
                }
            } else if (obj == enterForm) {
                if (c == BACK_CMD) {
                    display.setCurrent(ticketList);
                } else if (c == SAVE_CMD) {
                    updateAlert.set(ticketList.getTitle(), 
                                    enterText.getString());
                    display.setCurrent(alertMsg, aucMenu);
                }
            }
        } else if (s instanceof TextBox) {
            TextBox obj = (TextBox) s;
            if (obj == addBand) {
                if (c == BACK_CMD) {
                    display.setCurrent(setMenu);
                } else if (c == SAVE_CMD) {
                    updateBandList(addBand.getString());
                    display.setCurrent(savedMsg, setMenu);
                }
            }
        }
    }

}



